for
and repeat
loops. continueThe
exit [ with expression ]
continue
expression causes the closest enclosing for
or repeat
loop to immediately begin its next iteration. If there are no further iterations, the loop ends.for i in #(1, 3, 6, 9) do (
if (i * i) = 36 do continue
print i
)
1
3
9
If continue
is used in the collect
or select
forms of the for
loop, the value of the loop expression is not added to the collection if the loop is interrupted. For example:
for i := 1 to 5 collect (
if i = 3 then continue else i
)
#(1, 2, 4, 5)
The exit
expression is used to immediately stop execution of the innermost for
or repeat
loop, continuing the execution of the surrounding loop or block. Loops that are exited with exit
alone return undefined
. To specify a return value for the loop, use the exit
with
form. The return value of the entire block is then the value of expression.
val := for i in #(1, 3, 6, 9) do (
if i = 6 do exit with "Six"
print i
)
1
3
"Six"
print val
"Six"
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.